package com.hgyc.mom.common.context;

import com.hgyc.mom.common.exception.file.FileException;
import com.hgyc.mom.common.service.FileServiceStrategy;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

/**
 * 文件服务上下文
 * @author fwj
 * @since 2025/4/24
 */
@Service
public class FileServiceContext {

    private FileServiceStrategy fileServiceStrategy;

    public FileServiceContext(FileServiceStrategy fileServiceStrategy) {
        this.fileServiceStrategy = fileServiceStrategy;
    }

    public void setFileService(FileServiceStrategy fileServiceStrategy) {
        this.fileServiceStrategy = fileServiceStrategy;
    }

    public String uploadFile(MultipartFile file) throws FileException {
        return fileServiceStrategy.uploadFile(file);
    }

    public String uploadFile(MultipartFile file, String folder) throws FileException {
        return fileServiceStrategy.uploadFile(file, folder);
    }

    public byte[] downloadFile(String filePath) throws FileException {
        return fileServiceStrategy.downloadFile(filePath);
    }

    public void deleteFile(String filePath) throws FileException {
        fileServiceStrategy.deleteFile(filePath);
    }
}
